I have the following test...
it("basic test", () => {
stub = sinon.stub(app.mongoose, "connectMongoose").returns(Promise.resolve());
expect(val.listen.callCount).to.equal(0);
expect(stub.callCount).to.equal(0);
app.start();
expect(stub.callCount).to.equal(1);
expect(val.listen.callCount).to.equal(1);
stub.restore();
});
it("Error", () => {
stub = sinon.stub(app.mongoose, "connectMongoose").returns(Promise.reject(new Error("error")));
expect(val.listen.callCount).to.equal(0);
expect(stub.callCount).to.equal(0);
app.start();
expect(stub.callCount).to.equal(1);
expect(val.listen.callCount).to.equal(1);
stub.restore();
});
But when I run I get
TypeError: Attempted to wrap connectMongoose which is already wrapped
I also tried app.mongoose.connectMongoose.restore() but same result. I also tried sandboxes although those seem deprecated.
How do I restore so I can mock it again?